package com.excel;

import com.excel.model.CountryModel;
import com.excel.model.NationalityModel;
import com.excel.model.NonCrewImportModel;
import com.excel.utils.ExcelTemplateUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 伪代码，未实现具体功能
 *
 * @author wuan * @version ControllerDemo.java, v 0.1 2025-07-10 17:35 wuan@date 2025/07/10
 */
@RestController
public class ControllerDemo {

    @GetMapping("/generateTemplate")
    public void generateTemplate(HttpServletResponse response) {
        // 模拟从数据库查询数据
        List<String> nationalityList = new ArrayList<>();
        List<String> countryList = new ArrayList<>();
        // 将数据写入对应sheet页
        List<ExcelTemplateUtil.SheetConfig<?>> sheetConfigs = Arrays.asList(
                // 指定Sheet索引，确保顺序
                ExcelTemplateUtil.createSheet("In Chinese", NonCrewImportModel.class, null, 0),
                ExcelTemplateUtil.createSheet("Nationality", NationalityModel.class, nationalityList.stream().map(NationalityModel::new).collect(Collectors.toList()), 1),
                ExcelTemplateUtil.createSheet("Birth Country", CountryModel.class, countryList.stream().map(CountryModel::new).collect(Collectors.toList()), 2),
                ExcelTemplateUtil.createSheet("Birth Place", null, null, 3)
        );
        // 生成通用模板方法
        ExcelTemplateUtil.generateTemplate(response, "None Crew Template In Chinese", sheetConfigs);
    }
}